from urllib import response
import requests
import json


def get_result(input):
    url = 'http://49.232.174.87:8080/api/v0/generate'
    req_data = input
    rsp = requests.post(url, json=req_data)
    if rsp.status_code ==200:
        rsp_data = rsp.json()
        print(rsp_data)
    else:
        print(rsp.status_code)
    return rsp_data.get('texts')[0]

SPEAKER1 = ' [Human]:'#speaker 前要加一个空格不然，tokenizer会识别成两个字
SPEAKER2 = ' [Robot]:'
Intruction = "This is a discussion between a [Human] and a [Robot]. The [Robot] is very kind, empathtic and humous." + "\n"*5
#1# Sample = SPEAKER1 + "Otters are cute, this no one can deny. They have big eyes and snub snouts and paws like tiny leedle hands.\n"+\
#          SPEAKER2 + "ANIMALS\n"+\
#          SPEAKER1 + "Free, universal preschool for three- and four-year-olds is a key component of the Democrats’ agenda.\n"+\
#          SPEAKER2 + "EDUCATION\n"+\
#          SPEAKER1 + "In normal circumstances the Intergovernmental Panel on Climate Change (IPCC) can take media attention for granted.\n"+\
#          SPEAKER2 + "ENVIRONMENT\n"+\
#          SPEAKER1 + "Burberry has become the latest luxury brand to temporarily shut its stores in Russia following Moscow’s in\n"+\
#          SPEAKER2 + "FASHION\n"+\
#          SPEAKER1 + "Alibaba ‘s quarterly profit is expected to fall almost 60% year over year when the Chinese tech giant reports earnings on Thursday.\n"+\
#          SPEAKER2 + "BUSINESS\n"+\
#          SPEAKER1 + "Most EVS operate at 400 volts (400v). But a number of producers and their component suppliers are now gearing up to introduce 800v drive systems.\n"+\
#          SPEAKER2 + "TECH\n"+\
#          SPEAKER1 + "With only three weeks remaining in the 2021-22 NBA regular season, teams are starting to get down to the final 10-or-so games on their schedule.\n"+\
#          SPEAKER2 + "SPORT\n"
Sample = SPEAKER1 + "How do we learn?\n"+SPEAKER2 + "Through examining our mistakes.\n\n"+SPEAKER1 + "How do we get into the flow?\n"+SPEAKER2 + "By letting go of our ego and self absorption.\n\n"+SPEAKER1 + "How do we grow?\n"+SPEAKER2 + "Through connection and diversity.\n\n"+SPEAKER1 + "What is the purpose of suffering?\n"+SPEAKER2 + "To learn and grow.\n\n"
prompt = Intruction + Sample  + SPEAKER1 +"hello"+"\n" + SPEAKER2

# info = {"prompt":prompt,
#             "max_length":30,
#             'do_sample':True,
#             "top_p":0.7,
#             "top_k":10,
#             "temperature":0.9,
#             "stop_words":['\n','<|endoftext|>','['],
#             "min_length":5,
#             "length_penalty":1.0,
#             "repetition_penalty":1.3,
#}
info = dict(
    prompt=prompt,
    min_length=5,
    max_length=30,
    temperature=0.9,
    do_sample=True,
    top_p=0.7,
    top_k=10,
    stop_words = ['\n','<|endoftext|>','['],
    length_penalty=1.0,
    repetition_penalty=1.3,
    num_return_sequences=2
)

response = get_result(info)
print(response)